package com.example.human_resource_management.controller;

import com.example.human_resource_management.common.ResponseData;
import com.example.human_resource_management.config.UserContextUtils;
import com.example.human_resource_management.entry.po.Salary;
import com.example.human_resource_management.entry.po.Training;
import com.example.human_resource_management.service.SalaryService;
import com.example.human_resource_management.service.TrainingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/train")
public class TrainingController {
    @Autowired
    private TrainingService trainingService;

    // 员工查询所有培训内容
    @GetMapping("list")
    public ResponseData<List<Training>> getTrainingList() {
        List<Training> trainings = trainingService.selectTrainingList();
        return ResponseData.ok(trainings);
    }

    // 新增培训
    @PostMapping("add")
    public ResponseData<String> addTraining(@RequestBody Training training) {
        boolean success = trainingService.addTraining(training);
        return success ? ResponseData.ok("新增培训成功") : ResponseData.warn("新增培训失败");
    }

    // 修改培训
    @PutMapping("update")
    public ResponseData<String> updateTraining(@RequestBody Training training) {
        boolean success = trainingService.updateTraining(training);
        return success ? ResponseData.ok("修改培训成功") : ResponseData.warn("修改培训失败");
    }

    // 删除培训
    @DeleteMapping("delete/{trainId}")
    public ResponseData<String> deleteTraining(@PathVariable Long trainId) {
        boolean success = trainingService.deleteTraining(trainId);
        return success ? ResponseData.ok("删除培训成功") : ResponseData.warn("删除培训失败");
    }
}